package com.teacold.customdemo.chapter_one;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import com.teacold.customdemo.R;

public class CanvasCircle extends View {
    private Bitmap mBitmap;
    private Paint mPaint;
    private Path mPath;

    public CanvasCircle(Context context) {
        super(context);
        init();
    }

    public CanvasCircle(Context context, AttributeSet attrs) {
        this(context);
    }

    public CanvasCircle(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs);
    }
    private void init() {
     setLayerType(LAYER_TYPE_SOFTWARE,null);
     mBitmap=BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
     mPaint=new Paint();
     mPath=new Path();
     int width=mBitmap.getWidth();
     int height=mBitmap.getHeight();
     mPath.addCircle(width/2+50,height/2+50,width/3,Path.Direction.CCW);
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.save();
        canvas.clipPath(mPath);
        canvas.drawColor(Color.RED);
        canvas.drawBitmap(mBitmap,0,0,mPaint);
        canvas.restore();
    }



}
